package 序列化;

import java.io.*;

public class objectoutputstream方法 {
    public static void main(String[] args){
        File file=new File("e:\\yy.txt");
        Student s1=new Student("xiaowang",20,"wuhua");
        Student s2=new Student("xiaohe",20,"xishanqu");
        Student s3=new Student("xiaozhou",20,"guanduqu");
        try {
            ObjectOutputStream bb=new ObjectOutputStream(new FileOutputStream(file));
            bb.writeObject(s1);
            bb.writeObject(s2);
            bb.writeObject(s3);
            bb.close();
            ObjectInputStream cc=new ObjectInputStream(new FileInputStream(file));
            while (true){
                try {
                    Student s=(Student) cc.readObject();
                    System.out.println(s);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                    break;
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    }

